<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*
 * etc:短信接口
 * author:deepe.xiao
 */

require_once "qcloudsms/index.php";


use Qcloud\Sms\SmsSingleSender;
use Qcloud\Sms\SmsMultiSender;
use Qcloud\Sms\SmsVoiceVerifyCodeSender;
use Qcloud\Sms\SmsVoicePromptSender;
use Qcloud\Sms\SmsStatusPuller;
use Qcloud\Sms\SmsMobileStatusPuller;

use Qcloud\Sms\VoiceFileUploader;
use Qcloud\Sms\FileVoiceSender;
use Qcloud\Sms\TtsVoiceSender;

class Mysms
{

    private $appid;
    private $appkey;
    private $smsSign;
    function __construct()
    {
        if (empty(config_item("qqsms"))){
            view_log("致命错误","请在config.php文件中加入qqsms配置文件");
            die();
        }else{
            $qqsms = config_item("qqsms");
            if (empty($qqsms['appid']) || empty($qqsms['appkey'])){
                view_log("致命错误","请在qqsms配置项中加入appid与appkey参数");
                die();
            }
        }
        // 短信应用SDK AppID
        $this->appid = config_item("qqsms")['appid']; // 1400开头这个肯定要改成你自己的啦
        // 短信应用SDK AppKey
        $this->appkey = config_item("qqsms")['appkey'];//这个肯定要改成你自己的啦
        // 签名
        $this->smsSign = config_item("qqsms")['smsSign']; // NOTE: 这里的签名只是示例，请使用真实的已申请的签名，签名参数使用的是`签名内容`，而不是`签名ID`

    }

    /**
     * 发送短信验证码
     * @param String $phone
     * @param Integer $code
     * @param Integer $templateId 模板ID 此处填写的ID是演示的模板
     * @return array|void
     *
     */
    function sendsms($phone,$code,$templateId = 215850)
    {

        try {
            $ssender = new SmsSingleSender($this->appid, $this->appkey);
            $params = [$code,"30"];
            $result = $ssender->sendWithParam("86", $phone, $templateId,
                $params,$this->smsSign, "", "");  // 签名参数未提供或者为空时，会使用默认签名发送短信

            return objectToArray(json_decode($result));
        } catch(\Exception $e) {
            var_dump($e);
        }
    }

}
?>


